<template>
  <div class="C_ZDWH_ZDGJ">
    <div class="title">
      字典构建
    </div>
    <div class="query">
      创建日期：
      <el-date-picker
        type="daterange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOptions"
        size="small"
      >
      </el-date-picker>
      字典名称：
      <el-input size="small" class="input_style"></el-input>
      <el-button
        size="small"
        icon="el-icon-search"
        type="primary"
        style="margin-left:5px"
        >搜索</el-button
      >
      <el-button
        size="small"
        icon="el-icon-plus"
        type="primary"
        style="margin-left:5px"
        @click="open('add')"
        >新建</el-button
      >
    </div>
    <div class="main">
      <el-table
        :data="tableData"
        border
        height="700"
        style="width: 100%"
        :header-cell-style="{
          background: 'rgb(246,250,253)',
          color: '#000000',
        }"
      >
        <el-table-column prop="date" label="字典名称" width="160">
        </el-table-column>
        <el-table-column prop="address" label="处理类" width="180">
        </el-table-column>
        <el-table-column prop="address" label="所属包" width="160">
        </el-table-column>
        <el-table-column prop="address" label="描述"> </el-table-column>
        <el-table-column prop="address" label="创建者" width="160">
        </el-table-column>
        <el-table-column prop="address" label="创建日期" width="160">
        </el-table-column>
        <el-table-column prop="name" label="状态" width="80" align="center">
          <template slot-scope="scope">
            <el-tag type="success" effect="dark" size="mini">
              {{ scope.row.name }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              icon="el-icon-remove-outline"
              title="停用"
            ></el-button>
            <el-button
              type="text"
              icon="el-icon-edit"
              title="编辑"
              @click="open('edit', scope.row)"
            ></el-button>
            <el-button
              type="text"
              icon="el-icon-delete"
              title="删除"
            ></el-button>
            <el-button
              type="text"
              icon="el-icon-setting"
              title="字段设置"
              @click="dialogVisible_a = true"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="text-align:center;margin-top:5px">
        <el-pagination layout="prev, pager, next" :total="50"> </el-pagination>
      </div>
    </div>
    <!-- 弹层 -->
    <el-dialog
      :title="titleText"
      :visible.sync="dialogVisible"
      width="55%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <el-form
        label-position="right"
        label-width="150px"
        :model="formLabelAlign"
      >
        <el-form-item label="字典名称：">
          <el-input v-model="formLabelAlign.name"></el-input>
        </el-form-item>
        <el-form-item label="表前缀：">
          <el-input v-model="formLabelAlign.region"></el-input>
        </el-form-item>
        <el-form-item label="处理类名：">
          <el-input v-model="formLabelAlign.region"></el-input>
        </el-form-item>
        <el-form-item label="上级包名：">
          <el-input v-model="formLabelAlign.region"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input
            v-model="formLabelAlign.type"
            type="textarea"
            :rows="4"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="字段设置"
      :visible.sync="dialogVisible_a"
      width="85%"
      :before-close="handleClose_a"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <div class="title1">
        基础信息
      </div>
      <div class="box">
        <el-form
          label-position="right"
          label-width="300px"
          :model="formLabelAlign"
        >
          <el-form-item
            label="字典名称："
            style="width:45%;display:inline-block"
          >
            测试测试
          </el-form-item>
          <el-form-item label="表前缀：" style="width:45%;display:inline-block">
            测试测试
          </el-form-item>
          <el-form-item
            label="上级包名："
            style="width:45%;display:inline-block"
          >
            测试测试
          </el-form-item>
          <el-form-item
            label="处理类名："
            style="width:45%;display:inline-block"
          >
            测试测试
          </el-form-item>
          <el-form-item label="描述：" style="width:100%;display:inline-block">
            测试测试
          </el-form-item>
        </el-form>
      </div>
      <div class="title1">
        字段设置
        <el-button
          size="small"
          icon="el-icon-plus"
          style="float:right;margin-top:5px"
          @click="open1('add')"
        ></el-button>
      </div>
      <div class="box">
        <el-table
          :data="tableData"
          border
          height="250"
          style="width: 100%"
          :header-cell-style="{
            background: 'rgb(246,250,253)',
            color: '#000000',
          }"
        >
          <el-table-column prop="date" label="字段名" width="160">
          </el-table-column>
          <el-table-column prop="address" label="字段备注" width="180">
          </el-table-column>
          <el-table-column prop="address" label="字段长度" width="160">
          </el-table-column>
          <el-table-column prop="address" label="允许为空"> </el-table-column>
          <el-table-column prop="address" label="录入方式" width="160">
          </el-table-column>
          <el-table-column prop="address" label="录入顺序" width="160">
          </el-table-column>

          <el-table-column label="操作" width="180" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                icon="el-icon-edit"
                title="编辑"
                @click="open1('edit', scope.row)"
              ></el-button>
              <el-button
                type="text"
                icon="el-icon-delete"
                title="删除"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible_a = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible_a = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :title="titleText_info"
      :visible.sync="dialogVisible_b"
      width="75%"
      :before-close="handleClose_b"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" label-width="220px">
        <el-form-item label="字段名：">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="字段备注：">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="字段长度：">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="允许为空：">
          <el-radio-group v-model="form.resource">
            <el-radio label="是"></el-radio>
            <el-radio label="否"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="前台录入：">
          <el-radio-group v-model="form.resource">
            <el-radio label="是"></el-radio>
            <el-radio label="否"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="默认值：">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="前台录入方式：">
          <el-select v-model="form.region">
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="前台录入顺序：">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="关键外键：">
          select<el-input
            v-model="form.name"
            placeholder="KEY"
            class="input_style1"
          ></el-input
          >,<el-input
            v-model="form.name"
            placeholder="VALUE"
            class="input_style1"
          ></el-input
          >from<el-input
            v-model="form.name"
            placeholder="表名"
            class="input_style1"
          ></el-input
          >where<el-input
            v-model="form.name"
            placeholder="条件"
            class="input_style1"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible_b = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible_b = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  // 组件名称
  name: "",
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "已启用",
          address: "金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "已启用",
          address: "金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "已启用",
          address: "金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "已启用",
          address: "金沙江路 1516 弄",
        },
      ],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      formLabelAlign: {},
      dialogVisible: false,
      dialogVisible_a: false,
      dialogVisible_b: false,
      titleText: "",
      titleText_info: "",
      tableData_a: [
        {
          date: "测试数据测试数据",
          address: "123",
        },
      ],
      codes: [],
      formLabelAlign: {},
      form: {},
    };
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
   * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
   */
  created() {},
  /**
   * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
   * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
   */
  mounted() {},
  // 组件方法
  methods: {
    open(flag, val) {
      if (flag == "add") {
        this.titleText = "新增字典";
      }
      if (flag == "edit") {
        this.titleText = "编辑字典";
      }
      if (val) {
      }
      this.dialogVisible = true;
    },
    open1(flag, val) {
      if (flag == "add") {
        this.titleText_info = "新增字段";
      }
      if (flag == "edit") {
        this.titleText_info = "编辑字段";
      }
      if (val) {
      }
      this.dialogVisible_b = true;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleClose_a() {
      this.dialogVisible_a = false;
    },
    handleClose_a() {
      this.dialogVisible_b = false;
    },
    handleSelectionChange(val) {
      this.codes = val;
    },
    addPlus() {
      this.tableData_a.push({ date: "", address: "" });
    },
    del_row() {
      var that = this;
      this.codes.forEach((item) => {
        that.tableData_a.forEach((item2, index) => {
          if (item.address == item2.address) {
            this.tableData_a.splice(index, 1);
          }
        });
      });
    },
  },
};
</script>

<style scoped lang="scss">
.C_ZDWH_ZDGJ {
  .title {
    background-color: rgb(233, 242, 255);
    line-height: 45px;
    font-size: 18px;
    font-weight: 700;
    padding: 0 10px;
  }
  .query {
    margin: 0 10px;
    margin-top: 10px;
    padding: 5px;
    border: 1px solid #ccc;
    line-height: 40px;
  }
  .main {
    padding: 0 10px;
    margin-top: 10px;
  }
  .input_style {
    display: inline-block;
    width: 200px;
  }
}
.title1 {
  background-color: rgb(233, 242, 255);
  line-height: 45px;
  font-size: 18px;
  font-weight: 700;
  padding: 0 10px;
  border: 1px solid #ccc;
}
.box {
  padding: 10px;
  border: 1px solid #ccc;
}
.input_style1 {
  display: inline-block;
  width: 200px;
  margin: 0 5px;
}
</style>
